local M = {}

M.opts = function()
   local headers = {
      wave = {
         [[⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⡴⠶⠶⢦⣤⡀⣀⣀⣀⣀⣀⡀⣤⣶⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀]],
         [[⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣾⡋⠀⠀⠀⠀⠀⠼⠟⣻⣶⣾⣽⠋⠹⠿⣿⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀]],
         [[⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⠞⠡⠞⢻⠟⠛⠯⣅⣀⠀⠀⠉⠉⠀⠁⠀⠀⠀⠻⠟⠷⢦⣶⣶⣄⠀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀]],
         [[⠀⠀⠀⠀⠀⠀⠀⠀⢀⣾⣁⡄⠀⠀⠀⠀⠀⠀⠙⢻⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠓⠀⢾⣿⣽⣯⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀]],
         [[⠀⠀⠀⠀⠀⠀⢀⡴⠟⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⢁⣿⣇⣤⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀]],
         [[⠀⠀⠀⠀⠀⢠⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢿⠿⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀]],
         [[⠀⠀⠀⠀⢠⡾⠀⡶⠚⠀⠀⠀⠀⣀⠀⣠⣤⡀⠀⣴⢷⠀⣷⣀⠀⢠⣼⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⠤⠆⠀⢀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀]],
         [[⠀⠀⠀⠀⣿⢡⣼⠁⠀⠀⠀⠀⣾⣿⡿⠿⠋⠛⠓⠿⣦⣤⣿⣿⣷⣾⣿⣿⣶⣿⣿⠃⢀⠀⣶⣀⡄⠀⢻⣿⣿⣶⡾⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀]],
         [[⠀⠀⠀⢠⣧⡿⠃⠀⢠⢶⣶⡟⠀⠀⠀⠀⠀⠀⠀⠀⠉⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣮⣿⡿⢅⣵⣶⣤⣿⣿⡉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀]],
         [[⠀⠀⢠⣿⠟⠀⣰⣾⠿⣻⠟⠁⠀⠀⠀⠀⠀⠀⠀⣀⣶⣿⣿⣿⣿⣿⣿⣿⠿⢉⠉⣹⡿⢿⣿⣯⣯⢉⣟⡋⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀]],
         [[⠀⠀⠨⠏⣴⠞⠉⠉⠉⠁⠀⠀⠀⠀⠀⠀⢠⣤⣤⣿⣿⣿⣿⣿⣿⣿⣹⠃⠀⠘⢁⣽⣯⣯⡅⠼⠏⠸⢿⡇⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀]],
         [[⠀⢠⣇⣿⠏⠀⣼⣿⡾⠃⠀⠀⠀⠀⣠⣄⣟⣿⣿⣿⣿⣿⣟⣻⣿⣿⡏⠀⠀⠀⠈⠉⠃⠙⢿⡆⠀⠀⠀⠉⣧⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀]],
         [[⠀⠀⣾⡟⡗⣰⠿⠛⠀⠀⣀⣐⢻⣞⣿⣿⣿⣿⣿⣿⣾⡟⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠈⠁⠀⠀⠀⠀⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀]],
         [[⢀⣴⣫⣿⣷⠃⠀⠀⠀⠀⢳⣾⣿⣿⣿⣿⣿⡿⢿⣟⣿⣷⣿⣿⣿⡟⣷⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀]],
         [[⢸⣧⡄⠀⣬⠀⠀⠀⠀⣠⣴⣿⣿⣿⣿⣿⣿⡿⣮⣿⡏⠈⠀⠀⠈⣿⣮⣳⡄⠤⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣤⣶⡆⠀]],
         [[⠈⢻⣇⢠⠏⠀⠀⠀⢸⣿⣯⣿⣽⣿⣿⣿⠛⠙⠻⣿⠀⢀⣀⢀⠀⣿⣿⣿⠿⣢⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⣴⡶⢶⣆⣀⣤⣤⣴⣶⠿⠟⠋⠁⠀⡀]],
         [[⠀⢸⣏⣸⣤⠄⣴⣾⣿⢿⣿⣿⣿⠿⠉⠀⢠⣴⣗⡀⢀⣼⣿⣿⣿⠿⣞⠋⠳⢜⣳⢽⣛⣓⢀⣀⣶⣚⣻⣿⣿⠀⠘⣿⣿⣿⣿⡯⣴⣖⡷⢴⠚⠋⠀]],
         [[⠀⠈⠻⣼⢿⠘⠛⡟⢿⣄⢿⣿⡇⠀⠀⠀⢙⣿⣿⣿⣿⣿⣿⣷⡿⣷⡈⠳⢶⣚⠻⣷⣾⣿⣿⣧⠬⠿⣿⣿⣉⣿⣷⣿⣿⣿⣿⣿⣷⣤⠤⠀⠀⠀⠀]],
         [[⠀⠀⠀⠸⣾⠛⠀⣷⣿⣾⣿⠷⠂⠀⠀⠀⢹⣿⣿⣿⣿⣿⣯⣿⣝⢮⡙⢯⣅⡛⠻⠷⠿⢿⣿⣿⣿⣿⣿⡟⠉⢹⣿⣽⣿⡿⣿⡶⠶⠶⠂⢀⣤⠀⠀]],
         [[⠀⠀⠀⠀⠘⣇⡀⢻⣻⡟⠀⢠⣤⣤⣠⣤⣼⣿⣿⣿⣿⣿⣿⣿⡟⢿⣮⣍⠉⠉⠉⠛⠲⣶⣿⣿⣿⡿⠃⠀⠲⠟⣿⣷⣾⣻⣿⠿⠀⠈⠉⠁⠀⠀⠀]],
         [[⠀⠀⠀⠀⠀⠘⠻⣼⣿⣿⠀⠀⣿⣿⣿⣿⣿⣿⢻⡷⣌⠛⢿⢿⡛⠶⣬⣍⣑⣂⣀⣀⣠⣶⡶⠟⠉⠀⢀⣷⣶⣿⣟⢛⣛⡛⠉⠀⠀⠀⠀⠀⠀⠀⠀]],
         [[⠀⠀⠀⠀⠀⠀⠀⠘⠋⠛⢦⣀⣿⣿⣿⣿⣏⣿⣷⣝⣌⠳⡀⢀⠙⣖⣾⠟⠻⣟⣉⣉⣉⣉⣀⣀⣤⡖⠋⠉⠙⠛⢿⣿⣋⣿⣶⣶⣦⣤⡄⠀⠀⠀⠀]],
         [[⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠻⣿⣯⡿⣯⢿⡛⢫⣛⣻⣾⣿⣿⣴⡯⠷⣤⣄⠙⢻⡧⢤⡴⠶⢛⣁⣠⠄⠀⠀⢀⣠⣿⣿⣾⣿⣿⣭⡿⠇⠀⠀⠀⠀]],
         [[⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠓⠾⢾⣿⣶⣬⣿⣿⡽⠟⠀⠀⣼⣿⡟⠿⣦⣿⣦⣽⣾⠿⠷⠖⠛⠛⠋⠉⠀⠀⠉⠉⠉⠉⠁⠀⠀⠀⠀⠀⠀]],
         [[⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⠉⠈⠙⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀]],
      },
      shrek = {
         [[⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣤⣤⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀]],
         [[⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⠀⠀⠀⢀⣴⠟⠉⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⣤⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀]],
         [[⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣷⣀⢀⣾⠿⠻⢶⣄⠀⠀⣠⣶⡿⠶⣄⣠⣾⣿⠗⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀]],
         [[⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⢻⣿⣿⡿⣿⠿⣿⡿⢼⣿⣿⡿⣿⣎⡟⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀]],
         [[⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⡟⠉⠛⢛⣛⡉⠀⠀⠙⠛⠻⠛⠑⣷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀]],
         [[⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣿⣧⣤⣴⠿⠿⣷⣤⡤⠴⠖⠳⣄⣀⣹⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀]],
         [[⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣀⣟⠻⢦⣀⡀⠀⠀⠀⠀⣀⡈⠻⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀]],
         [[⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⡿⠉⡇⠀⠀⠛⠛⠛⠋⠉⠉⠀⠀⠀⠹⢧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀]],
         [[⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣾⡟⠀⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠃⠀⠈⠑⠪⠷⠤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀]],
         [[⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣾⣿⣿⣿⣦⣼⠛⢦⣤⣄⡀⠀⠀⠀⠀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠑⠢⡀⠀⠀⠀⠀⠀]],
         [[⠀⠀⠀⠀⠀⠀⠀⢀⣠⠴⠲⠖⠛⠻⣿⡿⠛⠉⠉⠻⠷⣦⣽⠿⠿⠒⠚⠋⠉⠁⡞⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⢦⠀⠀⠀⠀]],
         [[⠀⠀⠀⠀⠀⢀⣾⠛⠁⠀⠀⠀⠀⠀⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠤⠒⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢣⠀⠀⠀]],
         [[⠀⠀⠀⠀⣰⡿⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣑⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⡇⠀⠀]],
         [[⠀⠀⠀⣰⣿⣁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣾⣧⣄⠀⠀⠀⠀⠀⠀⢳⡀⠀]],
         [[⠀⠀⠀⣿⡾⢿⣀⢀⣀⣦⣾⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣾⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡰⣫⣿⡿⠟⠻⠶⠀⠀⠀⠀⠀⢳⠀]],
         [[⠀⠀⢀⣿⣧⡾⣿⣿⣿⣿⣿⡷⣶⣤⡀⠀⠀⠀⠀⠀⠀⠀⢀⡴⢿⣿⣧⠀⡀⠀⢀⣀⣀⢒⣤⣶⣿⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇]],
         [[⠀⠀⡾⠁⠙⣿⡈⠉⠙⣿⣿⣷⣬⡛⢿⣶⣶⣴⣶⣶⣶⣤⣤⠤⠾⣿⣿⣿⡿⠿⣿⠿⢿⣿⣿⣿⣿⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇]],
         [[⠀⣸⠃⠀⠀⢸⠃⠀⠀⢸⣿⣿⣿⣿⣿⣿⣷⣾⣿⣿⠟⡉⠀⠀⠀⠈⠙⠛⠻⢿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇]],
         [[⠀⣿⠀⠀⢀⡏⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⠿⠿⠛⠛⠉⠁⠀⠀⠀⠀⠀⠉⠠⠿⠟⠻⠟⠋⠉⢿⣿⣦⡀⢰⡀⠀⠀⠀⠀⠀⠀⠁]],
         [[⢀⣿⡆⢀⡾⠀⠀⠀⠀⣾⠏⢿⣿⣿⣿⣯⣙⢷⡄⠀⠀⠀⠀⠀⢸⡄⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⣿⣻⢿⣷⣀⣷⣄⠀⠀⠀⠀⢸⠀]],
         [[⢸⠃⠠⣼⠃⠀⠀⣠⣾⡟⠀⠈⢿⣿⡿⠿⣿⣿⡿⠿⠿⠿⠷⣄⠈⠿⠛⠻⠶⢶⣄⣀⣀⡠⠈⢛⡿⠃⠈⢿⣿⣿⡿⠀⠀⠀⠀⠀⡀]],
         [[⠟⠀⠀⢻⣶⣶⣾⣿⡟⠁⠀⠀⢸⣿⢅⠀⠈⣿⡇⠀⠀⠀⠀⠀⣷⠂⠀⠀⠀⠀⠐⠋⠉⠉⠀⢸⠁⠀⠀⠀⢻⣿⠛⠀⠀⠀⠀⢀⠇]],
         [[⠀⠀⠀⠀⠹⣿⣿⠋⠀⠀⠀⠀⢸⣧⠀⠰⡀⢸⣷⣤⣤⡄⠀⠀⣿⡀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡆⠀⠀⠀⠀⡾⠀⠀⠀⠀⠀⠀⢼⡇]],
         [[⠀⠀⠀⠀⠀⠙⢻⠄⠀⠀⠀⠀⣿⠉⠀⠀⠈⠓⢯⡉⠉⠉⢱⣶⠏⠙⠛⠚⠁⠀⠀⠀⠀⠀⣼⠇⠀⠀⠀⢀⡇⠀⠀⠀⠀⠀⠀⠀⡇]],
         [[⠀⠀⠀⠀⠀⠀⠻⠄⠀⠀⠀⢀⣿⠀⢠⡄⠀⠀⠀⣁⠁⡀⠀⢠⠀⠀⠀⠀⠀⠀⠀⠀⢀⣐⡟⠀⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⢠⡇]],
      },
   }

   local dashboard = require('alpha.themes.dashboard')

   dashboard.section.header.val = headers.shrek

   dashboard.section.buttons.val = {
      dashboard.button('f', ' ' .. ' Find file', ':Telescope find_files <CR>'),
      dashboard.button('e', ' ' .. ' New file', ':ene <BAR> startinsert <CR>'),
      dashboard.button(
         'p',
         ' ' .. ' Find project',
         ":lua require('telescope').extensions.projects.projects()<CR>"
      ),
      dashboard.button('r', '󰄉 ' .. ' Recent files', ':Telescope oldfiles <CR>'),
      dashboard.button('t', ' ' .. ' Find text', ':Telescope live_grep <CR>'),
      dashboard.button('c', ' ' .. ' Config', ':e $MYVIMRC <CR>'),
      dashboard.button('s', ' ' .. ' Restore Session', [[:lua require("persistence").load() <cr>]]),
      dashboard.button('l', '󰒲 ' .. ' Lazy', ':Lazy<CR>'),
      dashboard.button('q', ' ' .. ' Quit', ':qa<CR>'),
   }
   for _, button in ipairs(dashboard.section.buttons.val) do
      button.opts.hl = 'AlphaButtons'
      button.opts.hl_shortcut = 'AlphaShortcut'
   end

   dashboard.section.header.opts.hl = 'AlphaHeader'
   dashboard.section.buttons.opts.hl = 'AlphaButtons'
   dashboard.section.footer.opts.hl = 'AlphaFooter'
   dashboard.section.buttons.opts.position = 'right'
   dashboard.opts.opts.noautocmd = true

   return dashboard
end

M.config = function(_, dashboard)
   if vim.o.filetype == 'lazy' then
      vim.cmd.close()
      vim.api.nvim_create_autocmd('User', {
         pattern = 'AlphaReady',
         callback = function()
            require('lazy').show()
         end,
      })
   end

   require('alpha').setup(dashboard.opts)

   vim.api.nvim_create_autocmd('User', {
      pattern = 'LazyVimStarted',
      callback = function()
         local stats = require('lazy').stats()
         local ms = (math.floor(stats.startuptime * 100 + 0.5) / 100)
         dashboard.section.footer.val = '⚡ Neovim loaded ' .. stats.count .. ' plugins in ' .. ms .. 'ms'
         pcall(vim.cmd.AlphaRedraw)
      end,
   })
end

return M
